package com.my.hotel.controller.serverPage;

import com.my.hotel.entity.serverPage.JdUser;
import com.my.hotel.service.JdUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;



@Controller
@RequestMapping("/jd")
public class JdIndexController {
    @Autowired
    private JdUserService jdUserService;
    @RequestMapping("/jdPreUpdate")
    public String jdPreUpdate(HttpSession session, Model model){
        JdUser jduser = (JdUser)session.getAttribute("userInfo");
        JdUser jdUser = jdUserService.getClientById(jduser.getId());
        model.addAttribute("jdUser",jdUser);
        return "jdUserUpdate";
    }

    @Autowired
    UtilsController utilsController;
    @RequestMapping("/jdUpdate")
    public String jdUpdate(JdUser jdUser,Model model,HttpSession session){
        jdUserService.clientUpdate(jdUser);
        session.setAttribute("userInfo",jdUser);
        JdUser userinfo = (JdUser) session.getAttribute("userInfo");
        model.addAttribute("userInfo",userinfo);
        return utilsController.forwardToLogin(1,5,model);
//        return "serverPage/index";
    }
}
